iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 16
0

步驟說明

Step1: 打包客製化的 image

docker build -f docker/auth-server.Dockerfile --build-arg NODE_ENV=$_NODE_ENV -t gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA .

Step2: 將 image 上傳到 GCR 服務

docker push gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA .

Step3: 自動部署微服務

export CLOUDSDK_COMPUTE_ZONE=asia-east1-a
export CLOUDSDK_CONTAINER_CLUSTER=prod-cluster

kubectl set image deployment auth-deployment auth-server=gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA

完整的 production-auth-ci.yaml 檔案

steps:
  - name: "gcr.io/cloud-builders/docker"
    id: auth-build
    env: ["NODE_ENV=$_NODE_ENV"]
    args:
      - "build"
      - "-f"
      - "docker/auth-server.Dockerfile"
      - "--build-arg"
      - "NODE_ENV=$_NODE_ENV"
      - "-t"
      - "gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA"
      - "."

  - name: "gcr.io/cloud-builders/docker"
    id: auth-push
    args:
      - "push"
      - "gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA"

  - name: "gcr.io/cloud-builders/kubectl"
    args:
      - set
      - image
      - deployment
      - auth-deployment
      - auth-server=gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA
    env:
      - "CLOUDSDK_COMPUTE_ZONE=asia-east1-a"
      - "CLOUDSDK_CONTAINER_CLUSTER=prod-cluster"

延伸閱讀


上一篇
Staging 環境 CI/CD
下一篇
健康檢查
系列文
Microservices in Action: with example in Node.js24
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言